package org.sgx.gwteditors.client.editor.props;

import java.util.List;

import org.sgx.gwteditors.client.util.LWOMap;

public class PropertyHaverUtil {
public static List<String> getPropertyNames(PropertyHaver ph) {
	return ph.getProperties().keys();
}

public static LWOMap<String, PropertyInfo> buildPropMap(
		PropertyInfo[] propertyInfos) {
	LWOMap<String, PropertyInfo> m = new LWOMap<String, PropertyInfo>();
	for (int i = 0; i<propertyInfos.length; i++) {
		m.put(propertyInfos[i].getName(), propertyInfos[i]);
	}
	return m;
}

public static void print(PropertyHaver ph, StringBuffer sb) { 
	sb.append("PropertyHaver(");
	for(String name : ph.getProperties().keys()) {
		Object val = ph.propertyGet(name); 
		if(val instanceof PropertyHaver) 
			sb.append("(\n\t"); 
		sb.append(name+": "+ph.propertyGet(name)+", ");
		if(val instanceof PropertyHaver) 
			sb.append(")"); 
	}
	sb.append(")");
}

public static String print(PropertyHaver ph) {
	StringBuffer sb = new StringBuffer(); 
	print(ph, sb); 
	return sb.toString();
}

//public static PropertyHaver fromJSON(JsObject o) {
//	PropertyHaver ph = new AbstractPropertyHaver();
//	for (int i = 0; i < o.objProps().length(); i++) {
//		String propName = o.objProps().get(i);
//		//TODO
//	}
//	return ph;
//}

//public static JsObject toJSON(PropertyHaver ph) {
//	return null;//TODO
//}


}
